<!--#include file="../Lib/base.asp"-->
<!--#include file="../Lib/Page.asp"-->
<%

	dim datadb,datadb2
	dim i
	dim act:act=lcase(Cls.fget("act",0))
	select case act
		case "adddb":adddb
		case "editdb":editdb
		case "del":del
		case "delsome":delsome
	end select
	
	sub adddb()
		dim title,info,types,url,content,addtime,pic
		
		title=Cls.enhtml(Cls.fpost("title",0))
		info=cls.nohtml(Cls.enhtml(Cls.fpost("info",0)))
		types=Cls.enhtml(Cls.fpost("types",0))
		url=Cls.enhtml(Cls.fpost("url",0))
		content=Cls.fpost("content",0)
		pic=Cls.enhtml(Cls.fpost("pic",0))
		addtime=now()
		
		Dim data
		data=array(array("title",title,50,1),array("info",info,0,1),array("types",types,50,1),array("addtime",addtime,50,0),array("url",url,0,1),array("content",content,0,1),array("pic",pic,0,1))
		if Cls.db.dbnew("[sys_PicMsg]",data,"")=1 then
			Cls.echo "1"
		else
			Cls.echo "0数据出错"
		end if	
		Cls.die
	end sub
	
	
	sub editdb()
		dim title,info,types,url,content,addtime,pic
		dim id:id=Cls.getint(Cls.fget("id",0),0)
		
		title=Cls.enhtml(Cls.fpost("title",0))
		info=cls.nohtml(Cls.enhtml(Cls.fpost("info",0)))
		types=Cls.enhtml(Cls.fpost("types",0))
		url=Cls.enhtml(Cls.fpost("url",0))
		content=Cls.fpost("content",0)
		pic=Cls.enhtml(Cls.fpost("pic",0))
		
		Dim data
		data=array(array("title",title,50,1),array("info",info,0,1),array("types",types,50,1),array("url",url,0,1),array("content",content,0,1),array("pic",pic,0,1))
		if Cls.db.dbupdate("[sys_PicMsg]","id="&id,data)=1 then
			Cls.echo "1"
		else
			Cls.echo "0数据出错"
		end if	
		Cls.die	
	end sub
	
	
	sub del()
		dim id:id=Cls.getint(Cls.fget("id",0),0)
		if id>0 then
			Cls.db.dbdel "[sys_PicMsg]","id="&id&""			
			Cls.db.dbdel "[sys_KeyWord]","PicMsgID="&id&""	'删除关键字已指定的素材
			if Cls.db.dbloadone("PicMsgID","[sys_Config]","id=1")=id then		'删除关注回复已指定的素材
				call Cls.db.dbupdate("[sys_Config]","id=1",array(array("types","文本",50,1)))
			end if
		end if
		Cls.echo "1"
		Cls.die
	end sub
	
	sub delsome()
		dim id:id=Cls.enhtml(Cls.fget("id",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			Cls.echo "0至少选择一条信息"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					Cls.echo "0参数："&id(i)&"不正确，请确认后再操作"
					exit sub
				else							
					Cls.db.dbdel "[sys_KeyWord]","PicMsgID="&Cint(idarr(i))&""	'删除关键字已指定的素材	
					if Cls.db.dbloadone("PicMsgID","[sys_Config]","id=1")=Cint(idarr(i)) then		'删除关注回复已指定的素材
						call Cls.db.dbupdate("[sys_Config]","id=1",array(array("types","文本",50,1)))
					end if		
				end if
			next	
			Cls.db.dbdel "[sys_PicMsg]","id in("&id&")"
			Cls.echo "1"
		end if
		Cls.die
	end sub
	
%>
<!--#include file="../lib/Sys_Top.asp"-->
<script language="javascript" src="../lib/xheditor/xheditor-1.2.1.min.js"></script>
<script language="javascript" src="../lib/xheditor/xheditor_lang/zh-cn.js"></script>
<script>
function checkadd(the)
{
	if($.trim(the.title.value)=="")
	{
		$.message({content:"标题不能为空"});
		the.title.focus();
		return false;
	}
//	if($.trim(the.info.value)=="")
//	{
//		$.message({content:"简介不能为空"});
//		the.info.focus();
//		return false;
//	}
//	if($.trim(the.pic.value)=="")
//	{
//		$.message({content:"缩略图不能为空"});
//		the.pic.focus();
//		return false;
//	}
	if($('#types option:selected').val()=="链接")
	{
		if($.trim(the.url.value)=="")
		{
			$.message({content:"链接不能为空"});
			the.url.focus();
			return false;
		}
	}
	var url,data;
	url="?act=adddb";
	data="title="+encodeURIComponent($.trim(the.title.value));
	data+="&info="+encodeURIComponent($.trim(the.info.value));
	data+="&types="+encodeURIComponent($.trim(the.types.value));
	data+="&url="+encodeURIComponent($.trim(the.url.value));
	data+="&content="+encodeURIComponent(editor.getSource());
	data+="&pic="+encodeURIComponent($.trim(the.pic.value));
	
	$.ajax({
	type:"post",
	cache:false,
	url:url,
	data:data,
	error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
	success:function(_)
	{
		var act=_.substring(0,1);
		var info=_.substring(1);
		switch(act)
		{
			case "0":
				$.message({type:"error",content:info});
				break;
			case "1":
				$.message({type:"ok",content:"保存成功"});
				setTimeout("location.href='?'",1000);
				break;
			default:
				alert(_)
				break;
		}
	}
	});
	return false

}

function checkedit(the,id)
{
	if($.trim(the.title.value)=="")
	{
		$.message({content:"标题不能为空"});
		the.title.focus();
		return false;
	}
//	if($.trim(the.info.value)=="")
//	{
//		$.message({content:"简介不能为空"});
//		the.info.focus();
//		return false;
//	}
//	if($.trim(the.pic.value)=="")
//	{
//		$.message({content:"缩略图不能为空"});
//		the.pic.focus();
//		return false;
//	}
	if($('#types option:selected').val()=="链接")
	{
		if($.trim(the.url.value)=="")
		{
			$.message({content:"链接不能为空"});
			the.url.focus();
			return false;
		}
	}
	var url,data;
	url="?act=editdb&id="+id+"";
	data="title="+encodeURIComponent($.trim(the.title.value));
	data+="&info="+encodeURIComponent($.trim(the.info.value));
	data+="&types="+encodeURIComponent($.trim(the.types.value));
	data+="&url="+encodeURIComponent($.trim(the.url.value));
	data+="&content="+encodeURIComponent(editor.getSource());
	data+="&pic="+encodeURIComponent($.trim(the.pic.value));
	
	$.ajax({
	type:"post",
	cache:false,
	url:url,
	data:data,
	error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
	success:function(_)
	{
		var act=_.substring(0,1);
		var info=_.substring(1);
		switch(act)
		{
			case "0":
				$.message({type:"error",content:info});
				break;
			case "1":
				$.message({type:"ok",content:"保存成功"});
				setTimeout("location.href='?'",1000);
				break;
			default:
				alert(_)
				break;
		}
	}
	});
	return false

}
$(function(){
	$(".del").click(function(){
		var id=this.getAttribute('rel');
		var throughBox=$.dialog.through;
			throughBox({
				icon:'question',
				content:'确定要删除？不可恢复！删除图文素材将会连带删除与之关联的关键字！',
				lock:true,
				opacity:'0.5',
				ok:function(){
					var url='?act=del&id='+id;
					$.ajax({
					type:"get",
					cache:false,
					url:url,
					error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
					success:function(_)
					{
						if(_.substring(0,1)==0)
						{
							$.message({type:"error",content:_.substring(1)});
						}
						else
						{
							$.message({type:"ok",content:"删除成功"});
							$("#list_"+id).fadeOut('slow');
						}
					}
					});
									
					},
				cancelVal:'取消',
				cancel:true 
			})
		
		})
	
	$(".delsome").click(function(){
		    var arrchk=$("input[name='id']:checked");
			var idarr="";
			$(arrchk).each(function(){
				if(idarr==""){idarr+=this.value}else{idarr+=","+this.value}                   
			}); 
			if(idarr=="")
			{
				$.message({content:"至少选择一条信息"});
			}
			else
			{
				var throughBox=$.dialog.through;
				throughBox({
				icon:'question',
				content:'确定要删除？不可恢复！删除图文素材将会连带删除与之关联的关键字！',
				lock:true,
				opacity:'0.5',
				ok:function(){
					var url='?act=delsome&id='+idarr;
					$.ajax({
					type:"get",
					cache:false,
					url:url,
					error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
					success:function(_)
					{
						var act=_.substring(0,1);
						var info=_.substring(1);
						switch(act)
						{
							case "0":
								$.message({type:"error",content:info});
								break;
							case "1":
								$.message({type:"ok",content:"删除成功"});
								var idnum;
								idnum=idarr.split(",")
								for(i=0;i<=idnum.length;i++)
								{
									$("#list_"+idnum[i]).fadeOut('slow');
								}
								break;
							default:
								alert(_);
								break;
						}
					}
					});
									
					},
				cancelVal:'取消',
				cancel:true 
			})
			}
		})
	
 })


function setclose(t0)
{
	if(t0=="图文"){$("#type_url").css("display","none");$("#type_pic").css("display","block");}else{$("#type_url").css("display","block");$("#type_pic").css("display","none");}
}

var editor;
$(pageInit);
function pageInit()
{
    var allPlugin={
        GetPic:{c:'GetPic',t:'图片上传',e:function(){
            g = $.dialog.through;
			g({
				title: "图片上传",
				content: "<iframe src='../lib/upload.asp?filetype=1' width='560' height='400' frameborder='0' id='swfupload'></iframe>",
				padding: "10px",
				lock: !0,
				opacity: "0.5",
				ok: function() {
					var a = $("#att-status", art.dialog.top.$("#swfupload")[0].contentWindow.document).html();
					if (null != a) {
						var b, d;
						b = a.substring(0, 1),
						d = a.substring(1),
						editor.pasteHTML("<img src='"+d+"' />")
					}
				},
				cancelVal: "取消",
				cancel: !0
			})
        }}
    };
    editor=$('#content').xheditor({plugins:allPlugin,width:'510',height:'500',showBlocktag:true});
}
</script>
<style type="text/css">
<!--
.GetPic {
	background:transparent url(../images/icons2.png) no-repeat top left;
}
.btnMap {
	background:transparent url(../images/icons2.png) no-repeat top right;
}
-->
</style>

</head>
<body>
<div id="notice"><span>当前位置：</span>栏目 > <a href="?">图文素材</a></div>
	<%
	if act="edit" then	
	dim id:id=Cls.getint(Cls.fget("id",0),0)
	datadb=Cls.db.dbload("","title,info,pic,types,url,content","[sys_PicMsg]","id="&id,"")
	%>
    <script>	
	$(function(){
		$("#<%if datadb(3,0)="图文" then%>type_url<%else%>type_pic<%end if%>").css("display","none");
	})
	</script>
<div class="clear_fixed">
  <dl class="addlist">
    <form onSubmit="return checkedit(this,<%=id%>)">
      <dt><em>图文标题：</em>
        <input type="text" name="title" size="50" maxlength="50" value="<%=datadb(0,0)%>"/></dt>
      <dt><em>描述：</em>
        <textarea name="info" cols="60" rows="5"><%=datadb(1,0)%></textarea>
      </dt>
      <dt><em>缩略图：</em>
        <input type="text" name="pic" id="pic" size="50" value="<%=datadb(2,0)%>" /> <input type="button" value="上传" config="pic:1:0:1" class="bnt" /> 尺寸大小最好是360X200</dt>
      <dt><em>素材类型：</em>
        <select name="types" id="types" onChange="setclose(this.value)">
          <option value="图文" <%if datadb(3,0)="图文" then Cls.echo "selected"%>>图文</option>
          <option value="链接" <%if datadb(3,0)="链接" then Cls.echo "selected"%>>链接</option>
        </select>
        【链接】点击时直接链接到外部地址，【图文】直接显示内容</dt>
      <dt id="type_url"><em>外部链接：</em>
        <input type="text" name="url" size="80" value="<%=datadb(4,0)%>"/><br />
        1、设定链接，用户点击时会跳到此地址，需带http://<br />
2、链接发布后会在链接后台自动加入FromUserName这个参数，可以获得当前粉丝的OpenId，可用于自动绑定程序</dt>
      <dt id="type_pic"><em>图文内容：</em>
        <textarea name="content" id="content" cols="60" rows="5"><%=datadb(5,0)%></textarea>
      </dt>
      <dd>
        <input type="submit" name="send" value="保存" />
        <input type="button" value="返回" onClick="location.href='javascript:history.go(-1)'" />
      </dd>
    </form>
  </dl>
</div>
<%elseif act="add" then%>
<div class="clear_fixed">
  <dl class="addlist">
    <form onSubmit="return checkadd(this)">
      <dt><em>图文标题：</em>
        <input type="text" name="title" size="50" maxlength="50" /></dt>
      <dt><em>描述：</em>
        <textarea name="info" cols="60" rows="5"></textarea>
      </dt>
      <dt><em>缩略图：</em>
        <input type="text" name="pic" id="pic" size="50" /> <input type="button" value="上传" config="pic:1:0:1" class="bnt" /> 尺寸大小最好是360X200</dt>
      <dt><em>素材类型：</em>
        <select name="types" id="types" onChange="setclose(this.value)">
          <option value="图文">图文</option>
          <option value="链接">链接</option>
        </select>
        【链接】点击时直接链接到外部地址，【图文】直接显示内容</dt>
      <dt id="type_url" style="display:none"><em>外部链接：</em>
        <input type="text" name="url" size="50" value="http://"/><br>
        1、设定链接，用户点击时会跳到此地址，需带http://<br />
2、链接发布后会在链接后台自动加入FromUserName这个参数，可以获得当前粉丝的OpenId，可用于自动绑定程序</dt>
      <dt id="type_pic"><em>图文内容：</em>
        <textarea name="content" id="content" cols="60" rows="5"></textarea>
      </dt>
      <dd>
        <input type="submit" name="send" value="保存" />
        <input type="button" value="返回" onClick="location.href='javascript:history.go(-1)'" />
      </dd>
    </form>
  </dl>
</div>
<%else%>
<div class="clear_fixed">
  <div id="menu">
    <dl>
      <dt><span><a href="?act=add">添加素材</a></span></dt>
      <dt class="dropdown"><span><a href="javascript:;">批量操作↓</a></span>
        <ul>
          <li><a href="javascript:;" class="delsome">批量删除</a></li>
        </ul>
      </dt>
    </dl>
  </div>
  <form>
    <table cellpadding="5" id="table">
      <tr>
        <th width="20"><input type="checkbox" name="chkall" style="border:0;" onClick="checkall(this.form)" title="全选/取消" /></th>
        <th width="80">ID</th>
        <th width="100">类型</th>
        <th width="400">标题</th>
        <th>简介</th>
        <th width="200">添加时间</th>
        <th width="80">管理</th>
      </tr>
        <%
		Set Page = new Page_List
		Page.Con = Cls.db.conn		
		dim SqlStr:SqlStr="Select Id,Title,info,Addtime,types from [sys_PicMsg] order by id desc"
		Page.Sql = SqlStr
		Page.PageSize = 15
		Set Rs = Page.Rs
		
		If not Rs.Bof or Rs.Eof Then
			For i = 1 To Page.PageSize%>
      <tr id="list_<%=rs("id")%>">
        <td align="center"><input name="id" type="checkbox" style="border:0;" value="<%=rs("id")%>" /></td>
        <td align="center" ><%=rs("id")%></td>
        <td align="center"><%=rs("types")%></td>
        <td align="center"><a href="../Show.asp?id=<%=rs("id")%>" target="_blank"><%=rs("title")%></a></td>
        <td align="center" ><%=cls.cutstr(cls.nohtml(rs("info")),50,1)%></td>
        <td align="center" ><%=rs("addtime")%></td>
        <td align="center" ><a href="?act=edit&id=<%=rs("id")%>">编辑</a>　<a href="javascript:;" class="del" rel="<%=rs("id")%>">删除</a></td>
      </tr>
      <%
				Rs.MoveNext
			Next
		End If
		
		Call Page.ShowPage
		
		Rs.Close
		Set Rs = Nothing
		Set Page = Nothing%>
    </table>
  </form>
</div>
<%end if%>
</body>
</html>
